package cn.edu.zafu.bigdata.cccnnn.worktwo;

class Cube {
    private double length,width,height;

    //初始化
    public Cube(double length, double width, double height){
        this.length=length;
        this.width=width;
        this.height=height;
    }

    public double getLength(){
        return length;
    }

    public double getWidth(){
        return width;
    }

    public double getHeight(){
        return height;
    }

    public boolean equals(Object obj) {

        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }

        if (this == obj) {
            return true;
        }

        Cube other = (Cube) obj;

        return Double.compare(other.length, length) == 0 &&
                Double.compare(other.width, width) == 0 &&
                Double.compare(other.height, height) == 0;
    }

    public int hashCode() {
        // 使用Java 8引入的Objects类来生成hashCode
        return java.util.Objects.hash(length, width, height);
    }

 }



public class TestCube {
    public static void main(String[] args) {
        // 创建Cube对象
        Cube cube1 = new Cube(2.0, 3.0, 4.0);
        Cube cube2 = new Cube(2.0, 3.0, 4.0);
        Cube cube3 = new Cube(2.0, 3.0, 5.0);
        Cube cube4 = new Cube(3.0, 2.0, 4.0);

        // 测试相等性
        System.out.println("cube1 equals cube2: " + cube1.equals(cube2));
        System.out.println("cube1 equals cube3: " + cube1.equals(cube3));
        System.out.println("cube1 equals cube4: " + cube1.equals(cube4));
    }
}



